package com.sec.etech.employeesync.confighandler;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sec.etech.employeesync.entity.OrgEmployeeZEmployeeSubgroup;
import com.sec.etech.employeesync.mapper.OrgEmployeeZEmployeeSubgroupMapper;
import com.sec.etech.employeesync.util.ConfigTableHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class SubGroupConfigHandler implements ConfigTableHandler<OrgEmployeeZEmployeeSubgroup> {

    @Resource
    private OrgEmployeeZEmployeeSubgroupMapper subgroupMapper;

    @Override
    public Long getOrCreateConfigId(String... params) {
        String code = params[0];
        OrgEmployeeZEmployeeSubgroup subgroup = getEntityByName(code);
        if (subgroup == null) {
            return null;
        }
        return subgroup.getEmployeeSubgroupId();
    }

    @Override
    public OrgEmployeeZEmployeeSubgroup getEntityByName(String code) {
        return subgroupMapper.selectOne(Wrappers.<OrgEmployeeZEmployeeSubgroup>lambdaQuery()
                .eq(OrgEmployeeZEmployeeSubgroup::getCode, code));
    }

    @Override
    public String generateNextCode() {
        return null;
    }

    @Override
    public void insertEntity(OrgEmployeeZEmployeeSubgroup entity) {
        subgroupMapper.insert(entity);
    }
}
